/**
 * 作者：陈文斌 on 2019/1/3.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/component/Login/login_main_section.dart';
import 'package:crm/page/Login/crm_login_page.dart';

class LoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  @override
  Widget build(BuildContext context) {
    final double topPadding = MediaQuery.of(context).padding.top;
    final double bottomPadding = MediaQuery.of(context).padding.bottom;

    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Colors.white,
      body: new GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(new FocusNode()); // 触摸手气键盘
        },
        child: new Container(
          margin: EdgeInsets.only(
            top: topPadding,
            bottom: bottomPadding,
          ),
          width: AppScreen.setWidth(375),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              new Container(
                child: new Column(
                  children: <Widget>[
                    _closeSection(context),
                    _logoSection(),
                    LoginMainSection(),
                  ],
                ),
              ),
              _customerServiceSection(),
            ],
          ),
        ),
      ),
    );
  }
}

// 头部关闭按钮区域
Widget _closeSection(BuildContext context) {
  return Container(
      margin: EdgeInsets.only(top: 12, left: 12),
      child: Row(
        children: <Widget>[
          IconButton(
            icon: Icon(
              Icons.close,
              size: 30.0,
            ),
            onPressed: () {
              Navigator.pop(context);
            },
            color: Color.fromARGB(255, 112, 112, 112),
          ),
        ],
      ));
}

// logo区域
Widget _logoSection() {
  return new Container(
    width: AppScreen.setWidth(175),
    height: AppScreen.setHeight(90),
    child: new Image.asset(
      'images/LoginLogo.png',
    ),
  );
}

// 底部联系客服部分
Widget _customerServiceSection() {
  final String customerServiceMobile = '4008070666';
  // 拨打电话
  launchMobile() async {
    String mobile = 'tel:$customerServiceMobile';
    if (await canLaunch(mobile)) {
      await launch(mobile);
    }
  }

  return new Container(
    margin: EdgeInsets.only(bottom: 25.0),
    child: new RaisedButton(
      child: new Text(
        '客服电话：$customerServiceMobile',
        style: TextStyle(
          color: Color.fromARGB(255, 31, 140, 235),
          fontSize: 15.0,
        ),
      ),
      onPressed: launchMobile,
      color: Colors.white,
      elevation: 0.0,
      highlightElevation: 0.0,
      disabledElevation: 0.0,
      textTheme: ButtonTextTheme.normal,
      highlightColor: Colors.white,
      splashColor: Colors.white,
    ),
    height: 44.0,
  );
}
